package design.simdi.code.final_paper.utils;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.ResourceModel;

import design.simdi.code.final_paper.site.panels.PagePanel;

/**
 * 
 * @author Marius Dumitriu - (Jun 22, 2010 - 5:12:53 PM)
 * 
 */
public abstract class YesNoModalWindowPanel extends PagePanel {

	private static final long serialVersionUID = 1L;
	public static final String FORM = "forma";
	public static final String OK = "ok";
	public static final String CANCEL = "cancel";
	public static final String CONTENT = "intrebare";

	private AjaxButton buttonOK;
	private AjaxButton buttonCancel;
	private YesNoModalWindow yesNoModalWindow;
	@SuppressWarnings("unchecked")
	private Form form;

	public YesNoModalWindowPanel(String id, YesNoModalWindow yesNoModalWindow) {
		super(id);
		this.setYesNoModalWindow(yesNoModalWindow);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void panelInit() {
		form = new Form(FORM);

		buttonOK = new AjaxButton(OK, form) {

			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				getYesNoModalWindow().setModalResult(ModalResult.OK);
				onOK(target);

			}

		};
		buttonCancel = new AjaxButton(CANCEL, form) {

			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				getYesNoModalWindow().setModalResult(ModalResult.CANCEL);
				onCancel(target);

			}

		};

		add(buttonOK);
		add(buttonCancel);
		add(new Label(CONTENT, new ResourceModel("intrebare")));
		add(form);

	}

	public abstract void onOK(AjaxRequestTarget target);

	public abstract void onCancel(AjaxRequestTarget target);

	// public void setButtonOK(AjaxFallbackButton buttonOK) {
	// this.buttonOK = buttonOK;
	// }

	// public AjaxFallbackButton getButtonOK() {
	// return buttonOK;
	// }
	//
	// public void setButtonCancel(AjaxFallbackButton buttonCancel) {
	// this.buttonCancel = buttonCancel;
	// }

	// public AjaxFallbackButton getButtonCancel() {
	// return buttonCancel;
	// }

	@SuppressWarnings("unchecked")
	public void setForm(Form form) {
		this.form = form;
	}

	@SuppressWarnings("unchecked")
	public Form getForm() {
		return form;
	}

	public void setYesNoModalWindow(YesNoModalWindow yesNoModalWindow) {
		this.yesNoModalWindow = yesNoModalWindow;
	}

	public YesNoModalWindow getYesNoModalWindow() {
		return yesNoModalWindow;
	}

}
